package com.plant.oss.controller;

import com.plant.common.result.Result;
import com.plant.common.result.ResultCodeEnum;
import com.plant.oss.service.OssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author:查鑫杰
 * @Classname:OssController
 * @Date:2024/08/21
 * @Description:
 */

@RestController
@Slf4j
@RequestMapping("/oss")
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * 上传头像
     */
    @PostMapping("/fileoss")
    public Result uploadOSSFile(MultipartFile file) {
        //获取上传文件 MultipartFile
        //返回上传到oss的路径
        log.info("file==========================={}", file);
        String url = ossService.uploadFileAvatar(file);
        log.info("url==========================={}", url);
        if (url==null&&url.isEmpty()){
            return Result.build(url, ResultCodeEnum.FAIL);


        }
        return Result.build(url, ResultCodeEnum.SUCCESS);

    }
}
